package com.lgb.controller.admin;

import com.lgb.Service.MessageService;
import com.lgb.pojo.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.Date;

@Controller
public class MessageController {

    @Autowired
    private MessageService messageService;

    //接收用户留言
    @PostMapping("/message")
    public String message(Message message , RedirectAttributes redirectAttributes){
        //设置message的跟新时间
        message.setCreateTime(new Date());
        //设置message为未阅览
        message.setisRead(false);
        //保存
        messageService.saveMessage(message);
        redirectAttributes.addFlashAttribute("success_message" , "我会看的！！！");
        return "redirect:/";
    }

    //删除用户留言
    @GetMapping ("/delete_message/{id}")
    public String delete_message(@PathVariable Long id , RedirectAttributes redirectAttributes){
        messageService.deleteMessage(id);
        return "redirect:/admin/admin_index";
    }

}
